﻿using AcadRibbon.Ribbons.Json;
using AcadRibbon.Ribbons.Json.Model;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media.Imaging;
using System.Xml.Linq;

namespace Demo
{
    internal class CreateRibbonDemo {
        public static void Create() {
            RibbonTab tab = new RibbonTab();
            tab.Title = "绘图2";
            tab.Id = "CBA8DEBC-FA13-4CB2-A8FC-A4B4D3EDC58F";
            tab.Name = "绘图2_Home";
            tab.IsActive = true;

            RibbonPanel ribbonPanel = new RibbonPanel();
            tab.Panels.Add(ribbonPanel);

            RibbonPanelSource panelSource = new RibbonPanelSource();
            panelSource.Title = "绘图";
            ribbonPanel.Source = panelSource;

            RibbonButton ribbonButton = new RibbonButton();
            ribbonButton.Text = "直线";
            ribbonButton.Orientation = Orientation.Vertical;
            ribbonButton.ShowText = true;
            ribbonButton.ShowImage = true;
            ribbonButton.Size = Autodesk.Windows.RibbonItemSize.Large;
            ribbonButton.CommandParameter = "Line";
            ribbonButton.CommandHandler = "BEnvironmentSet";
            ribbonButton.LargeImage = "Images\\电气图.svg";
            //ribbonButton.Image = "Images\\Save.svg";
            panelSource.Items.Add(ribbonButton);

            //行
            RibbonRowPanel rowPanel = new();
            panelSource.Items.Add(rowPanel);


            ribbonButton = new RibbonButton();
            ribbonButton.Text = "移动";
            ribbonButton.Orientation = Orientation.Horizontal;
            ribbonButton.ShowText = true;
            ribbonButton.ShowImage = true;
            ribbonButton.Size = Autodesk.Windows.RibbonItemSize.Standard;
            ribbonButton.CommandParameter = "Move";
            ribbonButton.CommandHandler = "BEnvironmentSet";
            ribbonButton.Image= "Images\\电气图.svg";
            rowPanel.Items.Add(ribbonButton);

            //换行
            rowPanel.Items.Add(new RibbonRowBreak());
            ribbonButton = new RibbonButton();
            ribbonButton.Text = "复制";
            ribbonButton.Orientation = Orientation.Horizontal;
            ribbonButton.ShowText = true;
            ribbonButton.ShowImage = true;
            ribbonButton.Size = Autodesk.Windows.RibbonItemSize.Standard;
            ribbonButton.CommandParameter = "Copy";
            ribbonButton.CommandHandler = "BEnvironmentSet";
            ribbonButton.Image = "Images\\small.svg";
            rowPanel.Items.Add(ribbonButton);

            rowPanel.Items.Add(new RibbonRowBreak());
            ribbonButton = new RibbonButton();
            ribbonButton.Text = "拉伸";
            ribbonButton.Orientation = Orientation.Horizontal;
            ribbonButton.ShowText = true;
            ribbonButton.ShowImage = true;
            ribbonButton.Size = Autodesk.Windows.RibbonItemSize.Standard;
            ribbonButton.CommandParameter = "Stretch";
            ribbonButton.CommandHandler = "BEnvironmentSet";
            ribbonButton.Image = "Images\\small.svg";
            rowPanel.Items.Add(ribbonButton);



            var baseFolder = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
            baseFolder = Path.Combine(baseFolder, "ribbonconfig.json");
            
            var serializerSettings = new JsonSerializerSettings() {
                DefaultValueHandling = DefaultValueHandling.Ignore,
                NullValueHandling = NullValueHandling.Ignore,
            };
            var content = JsonConvert.SerializeObject(tab, Formatting.Indented, serializerSettings);
            File.WriteAllText(baseFolder, content);

        }
    }
}
